package com.material.vtool.service.impl;

import com.github.pagehelper.PageHelper;
import com.material.vtool.entity.BUserInfoEntity;
import com.material.vtool.entity.combinedEntity.CombinedCommonArticleEntity;
import com.material.vtool.entity.combinedEntity.CombinedUserDownloadMaterialEntity;
import com.material.vtool.entity.combinedEntity.CombinedUserShareMaterialEntity;
import com.material.vtool.mapper.UserInfoMapper;
import com.material.vtool.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserInfoServiceImpl implements UserInfoService {
    @Autowired
    private UserInfoMapper userInfoMapper;


    @Override
    public BUserInfoEntity getUserInfoByUserId(String userId) {
        return userInfoMapper.getUserInfoByUserId(userId);
    }

    @Override
    public int updateUserInfo(BUserInfoEntity entity) {
        return userInfoMapper.updateUserInfo(entity);
    }

    @Override
    public String getUserOpenId(int userId) {
        return userInfoMapper.getUserOpenId(userId);
    }

    @Override
    public Integer getUserIdByOpenId(String openId) {
        return userInfoMapper.getUserIdByOpenId(openId);
    }

    @Override
    public int addWxUserInfo(BUserInfoEntity entity) {
        return userInfoMapper.addUserInfo(entity);
    }

    @Override
    public int modifyWxUserInfo(BUserInfoEntity entity) {
        return userInfoMapper.modifyWxUserInfo(entity);
    }

    @Override
    public List<CombinedUserShareMaterialEntity> getUserShareList(Integer pageNum, Integer pageSize, Integer userId) {
        PageHelper.startPage(pageNum, pageSize);
        return userInfoMapper.getUserShareList(userId);
    }

    @Override
    public int getUserShareListTotal(Integer userId) {
        Integer affectedCount = userInfoMapper.getUserShareListTotal(userId);
        return affectedCount == null ? 0 : affectedCount.intValue();
    }

    @Override
    public List<CombinedUserDownloadMaterialEntity> getUserDownloadList(Integer pageNum, Integer pageSize, Integer userId) {
        PageHelper.startPage(pageNum, pageSize);
        return userInfoMapper.getUserDownloadList(userId);
    }

    @Override
    public int getUserDownloadListTotal(Integer userId) {
        Integer affectedCount = userInfoMapper.getUserDownloadListTotal(userId);
        return affectedCount == null ? 0 : affectedCount.intValue();
    }
}
